<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改设备管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-astDevice-edit" th:object="${astDevice}">
            <input name="deviceId" th:field="*{deviceId}" type="hidden">
            <input type="hidden" id="imgList" name="imgList" th:field="*{imgList}">
            <div class="form-group">
                <label class="col-sm-3 control-label">选择库房：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="storeroomId" type="hidden" th:field="*{storeroomId}" />
                        <input class="form-control" type="text" onclick="selectAstStoreroomTree()" id="treeName" readonly="true" th:field="*{storeroomName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">选择站点：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="siteId" name="siteId" type="hidden" th:field="*{siteId}" />
                        <input class="form-control" type="text" onclick="selectAstSiteTree()" id="siteName" readonly="true" th:field="*{siteName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">设备名称：</label>
                <div class="col-sm-8">
                    <input name="deviceName" th:field="*{deviceName}" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">设备类型：</label>
                <div class="col-sm-8">
                    <select name="deviceType" class="form-control m-b" th:with="type=${@dict.getType('ast_device_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{deviceType}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">单价：</label>
                <div class="col-sm-8">
                    <input name="devicePrice" th:field="*{devicePrice}" class="form-control" type="number">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">型号：</label>
                <div class="col-sm-8">
                    <input name="deviceGuige" th:field="*{deviceGuige}" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">设备厂家：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" name="deviceFactory" th:field="*{deviceFactory}" type="text" id="deviceFactory" >
                        <span onclick="selectFactoryTree()" class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label ">采购时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="deviceProcureTime" th:value="${#dates.format(astDevice.deviceProcureTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" >
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">质保时长(年)：</label>
                <div class="col-sm-8">
                    <input name="warrantyDuration" th:field="*{warrantyDuration}" class="form-control" type="number">
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">设备状态：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <div class="radio-box" th:each="dict : ${@dict.getType('ast_device_status')}">-->
<!--                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">-->
<!--                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->

            <div class="form-group">
                <label class="col-sm-3 control-label">协议模式：</label>
                <div class="col-sm-8">
                    <input name="protocolMode" class="form-control" type="text" th:field="*{protocolMode}">
                </div>
            </div>

            <div class="form-group">
                <label class="font-noraml">设备图片：</label>
                <div class="file-loading">
                    <input id="multipleFile" name="files" type="file" multiple>
                </div>
            </div>

            <div id="reasonDiv" style="display: none;" class="form-group">
                <label class="col-sm-3 control-label">操作说明：</label>
                <div class="col-sm-8">
                    <textarea name="reason" class="form-control">[[*{reason}]]</textarea>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "asset/astDevice";
        $("#form-astDevice-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-astDevice-edit').serialize());
            }
        }

        $("input[name='deviceProcureTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function () {
            $('input[type=radio][name=status]').change(function() {
                if ($(this).is(':checked')) {
                    //console.log('选中的值：', $(this).val());
                    $("#reasonDiv").css("display","block");
                    $("#caozuoState").val("1")
                }
            });
        })

        /*库房管理-编辑-选择父库房管理树*/
        function selectAstStoreroomTree() {
            var options = {
                title: '库房选择',
                width: "380",
                url: ctx + "asset/astStoreroom/selectAstStoreroomTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        function selectFactoryTree() {
            var options = {
                title: '厂商选择',
                width: "380",
                url: ctx + "asset/astFactory/selectFactoryTree" ,
                callBack: doSubmit2
            };
            $.modal.openOptions(options);
        }
        function doSubmit2(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#deviceFactory").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        /*站点管理-新增-选择父站点管理树*/
        function selectAstSiteTree() {
            var options = {
                title: '站点管理选择',
                width: "380",
                url: ctx + "asset/astSite/selectAstSiteTree/" + $("#treeId").val(),
                callBack: doSubmitSite
            };
            $.modal.openOptions(options);
        }

        function doSubmitSite(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#siteId").val(body.find('#treeId').val());
            $("#siteName").val(body.find('#treeName').val());
            $.modal.close(index);
        }

        var imgVal = $("#imgList").val()
        if(imgVal){
            imgVal = imgVal.split(",")
        }
        $("#multipleFile").fileinput({
            uploadUrl: ctx + 'common/uploads',
            uploadAsync: false,
            initialPreviewAsData: true,
            initialPreview: imgVal,
            // initialPreviewConfig:[{key:0,url:"http://localhost/profile/upload/2024/07/25/3_20240725160544A009.jpg"},{key:1,url:"http://localhost/profile/upload/2024/07/25/3_20240725160544A009.jpg"}]
        }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
            var rsp = data.response;
            var imgList = $("#imgList").val()
            if(imgList){
                imgList = imgList+","+rsp.urls
                $("#imgList").val(imgList)
            }else{
                $("#imgList").val(rsp.urls)
            }
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')


        }).on('fileclear', function (event, id, index) {
            $("#imgList").val("")
        })
        $("#multipleFile").fileinput('_initFileActions');

    </script>
</body>
</html>